<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>${webInfo.title}</title>
    <link href="${webInfo.logoImg}" rel="icon">
    <link rel="stylesheet" href="${ctxPath}/assets/css/login.css"/>
    <link rel="stylesheet" type="text/css" href="${ctxPath}/assets/aj-captcha/verify.css">
    <% include("./common/css.html"){} %>
    <script>
        if (window != top)
            top.location.replace(location.href);
    </script>
    <style>
        .logincard{
            background-color:rgba(255,255,255,0.2);
            box-shadow:0 1px 2px 0 rgba(0, 0, 0, .05)
        }

        .logincard .layui-card-header{
            border-bottom:0px;
            color: black;
        }

        .login_face{
            margin:0 auto; margin-bottom: -120px; width:80px; height:80px; -webkit-border-radius:50%; -moz-border-radius:50%;
            border-radius:50%;
            overflow:hidden;
        }
        .login_face img{ width:100%;}

        .slider-bg-green {
            background-color: #5FB878 !important
        }

        .login_input {
            height: 38px !important;
            border-radius: 2px !important;
        }

    </style>
</head>

<body style="background-image: url('${webInfo.loginBg}')">
<div class="login-wrapper">

    <div class="login-header">
    </div>

    <div class=" login-body" style="margin-top: 85px;">
        <div class="login_face" style="z-index:999;"><img src="${webInfo.logoImg}"></div>
        <div class="layui-card logincard" style="z-index:-1;">
            <div class="layui-card-header" style="text-align: center;height: 75px;line-height: 115px;font-size: 18px;">
                <strong>${webInfo.name}</strong>
            </div>
            <div class="layui-card-body layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-username"></i></label>
                    <div class="layui-input-block">
                        <input id="username" name="username" type="text" class="layui-input login_input" placeholder="账号" lay-verType="tips"
                               lay-verify="required"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-password"></i></label>
                    <div class="layui-input-block">
                        <input id="password" name="password" type="password" class="layui-input login_input" placeholder="密码"
                               lay-verType="tips" lay-verify="required"/>
                    </div>
                </div>
                <!--<div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-next"></i></label>
                    <div id="slider"></div>
                    <input name="code" type="hidden" id="code" class="layui-input" />
                </div>-->
                <!--<div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-vercode"></i></label>
                    <div class="layui-input-block">
                        <div class="layui-row inline-block">
                            <div class="layui-col-xs7">
                                <input name="code" type="text" class="layui-input login_input" placeholder="验证码" lay-verType="tips"
                                       lay-verify="required"/>
                            </div>
                            <div class="layui-col-xs5" style="padding-left: 10px;">
                                <img class="login-captcha" src="${ctxPath }/assets/captcha">
                            </div>
                        </div>
                    </div>
                </div>-->
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid layui-btn-radius" id='loginBtn'>登 录</button>
                    <div id="mpanel" style="margin-top:50px;"></div>
                </div>
            </div>
        </div>
    </div>

    <div class="login-footer">
        <p>© 2020 <a href="${webInfo.domain}" target="_blank">${webInfo.name} 版权所有 1.4.0</a></p>
        <!--<p>
            <span><a href="${webInfo.domain}" target="_blank">前往官网</a></span>
            <span><a href="${webInfo.domain}" target="_blank">联系我们</a></span>
            <span><a href="${webInfo.domain}" target="_blank">版权说明</a></span>
        </p>-->
    </div>
</div>

<script type="text/javascript" src="${ctxPath}/assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/libs/jquery/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/aj-captcha/crypto-js.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/aj-captcha/ase.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/aj-captcha/verify.js"></script>
<script>
    layui.config({
        base: 'assets/module/'
    }).extend({
        notice:'notice/notice'
    }).use(['layer', 'form', 'index','notice'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var index = layui.index;
        var notice = layui.notice;

        //项目根目录
        function projectUrl() {
            var layuiDir = layui.cache.dir;
            if (!layuiDir) {
                var js = document.scripts, last = js.length - 1, src;
                for (var i = last; i > 0; i--) {
                    if (js[i].readyState === 'interactive') {
                        src = js[i].src;
                        break;
                    }
                }
                var jsPath = src || js[last].src;
                layuiDir = jsPath.substring(0, jsPath.lastIndexOf('/') + 1);
            }
            return layuiDir.substring(0, layuiDir.indexOf('assets'));
        }


        // // 初始化验证码  弹出式
        $('#mpanel').pointsVerify({
            // baseUrl: 'http://10.108.12.4:8088',
            baseUrl: projectUrl(),  //服务器请求地址, 默认地址为安吉服务器;
            containerId: 'loginBtn', // pop模式 必填 被点击之后出现行为验证码的元素id
            mode: 'pop',
            imgSize: {       //图片的大小对象
                width: '350px',
                height: '170px',
            },
            beforeCheck: function () {  //检验参数合法性的函数  mode ="pop"有效
                // var flag = true;
                // //实现: 参数合法性的判断逻辑, 返回一个boolean值
                // return flag
                var name = $("#username").val()
                var pass = $('#password').val()
                if (name == '' || pass == '') {
                    notice.msg('请输入用户名或密码', {icon: 2});
                    return false
                } else {
                    return true
                }
            },
            ready: function () {
            },
            success: function (params) {
                //返回的二次验证参数 合并到验证通过之后的逻辑 参数中回传服务器
                layer.load(2);
                $.post('login', {
                    username: $("#username").val(),
                    password: $('#password').val(),
                    captcha: params.captchaVerification
                }, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg('恭喜，登录成功！', {icon: 1, time: 1000}, function () {
                            index.clearTabCache();
                            location.replace('./');
                        });
                    } else {
                        notice.msg(res.msg, {icon: 2});
                    }
                }, 'json');

            },
            error: function () {
            }
        });


        // 表单提交
        form.on('submit(loginSubmit)', function (obj) {
            layer.load(2);
            $.post('login', obj.field, function (res) {
                layer.closeAll('loading');
                if (200 == res.code) {
                    layer.msg('恭喜，登录成功！', {icon: 1, time: 1000}, function () {
                        index.clearTabCache();
                        location.replace('./');
                    });
                } else {
                    // layer.msg(res.msg, {icon: 5});
                    notice.msg(res.msg, {icon: 2});
                    // $('.login-captcha').trigger('click');
                }
            }, 'JSON');
            return false;
        });

        // 图形验证码
        $('.login-captcha').click(function () {
            this.src = this.src + '?t=' + (new Date).getTime();
        });


        /**浏览器记住密码，偶尔不能点击输入框的问题*/
        var i =document.getElementsByName("username");
        i = i[0];
        i.onfocus=function(){i.value = i.value +""};
        var j =document.getElementsByName("password");
        j = j[0];
        j.onfocus=function(){j.value = j.value +""};

    });
</script>
</body>
</html>